 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUI.java
 *
 * Created on 15.2.2010, 16:54:
 */

package com.example;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import javax.swing.JFileChooser;

/**
 *
 * @author Solev
 */

/*
 *
Command-line arguments for Attempto Parsing Engine:
-text "TEXT"        The input ACE text. If neither -text nor -file is present then the ACE text is read from stdin.
-file FILENAME      The name or URL of the input file containing the ACE text.
-ulextext "TEXT"    The user lexicon (taken from a string).
-ulexfile FILENAME  The user lexicon (taken from a file or URL).
 *
-solo OUTPUT        Output just one output component. OUTPUT has to be one of {paraphrase,paraphrase1,paraphrase2,owlfss,owlfsspp,owlrdf,owlxml,fol,pnf,tptp,tokens,syntax,syntaxpp,syntaxd,syntaxdpp,drs,drsxml,drspp,drshtml}.
-cdrs               Output the DRS as a Prolog term.
-cdrsxml            Output the DRS in XML.
-cdrspp             Output the DRS in pretty-printed form in plain text.
-cdrshtml           Output the DRS in pretty-printed form in HTML.
-cparaphrase        Output a paraphrase which is a "best-effort" combination of paraphrase1 and paraphrase2.
-cparaphrase1       Output a paraphrase which uses full sentences instead of relative clauses.
-cparaphrase2       Output a paraphrase which uses relative clauses instead of full sentences.
-ctokens            Output tokens as a Prolog list of lists.
-csentences         Output sentences as a Prolog list.
-csyntax            Output simplified syntax trees as a Prolog list.
-csyntaxpp          Output simplified syntax trees in pretty-printed form.
-csyntaxd           Output plain syntax trees as a Prolog list (for debugging).
-csyntaxdpp         Output plain syntax trees in pretty-printed form (for debugging).
-cowlfss            Output OWL 2 in the Functional-Style Syntax representation (as Prolog term).
-cowlfsspp          Output OWL 2 in the Functional-Style Syntax representation (pretty-printed).
-cowlrdf            Output OWL 2 in the RDF/XML representation.
-cowlxml            Output OWL 2 in the XML representation.
-cfol               Output standard first-order logic representations (default form) of the DRS as a Prolog term.
-cpnf               Output standard first-order logic representations (prenex normal form) of the DRS as a Prolog term.
-ctptp              Output TPTP representation of the DRS.
 *
-uri URI            URI for the OWL outputs.
-noclex             Ignore the lexicon entries that are compiled into the executable.
-guess              Guess the word-class of unknown words.
-server             Launch a socket interface to APE at port 2766 (0xACE).
-httpserver         Launch an HTTP interface to APE at port 8000.
-port NUMBER        Override the default port of either the socket or the HTTP interface.
-version            Shows version information.
-help               Shows this help page.
 *
 */
public class GUI extends javax.swing.JFrame {

    /** Creates new form GUI */
    public GUI() {
        initComponents();
    }

    String rezultat = "";

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        txtInput = new javax.swing.JTextField();
        btnParse = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaResult = new javax.swing.JTextArea();
        chbParaphrase = new javax.swing.JCheckBox();
        chbDRSProlog = new javax.swing.JCheckBox();
        chbDRSXML = new javax.swing.JCheckBox();
        chbTPTP = new javax.swing.JCheckBox();
        chbFOL = new javax.swing.JCheckBox();
        chbOWLProlog = new javax.swing.JCheckBox();
        chbTokens = new javax.swing.JCheckBox();
        chbOWLPP = new javax.swing.JCheckBox();
        chbSynTrees = new javax.swing.JCheckBox();
        chbGuess = new javax.swing.JCheckBox();
        chbOWLXML = new javax.swing.JCheckBox();
        chbOWLRDF = new javax.swing.JCheckBox();
        chbSynTreesPPDeb = new javax.swing.JCheckBox();
        chbSynTreesDeb = new javax.swing.JCheckBox();
        chbSynTreesPP = new javax.swing.JCheckBox();
        chbSents = new javax.swing.JCheckBox();
        chbDRSHTML = new javax.swing.JCheckBox();
        chbDRSPT = new javax.swing.JCheckBox();
        chbParaphrase2 = new javax.swing.JCheckBox();
        chbParaphrase1 = new javax.swing.JCheckBox();
        chbFOLPrenex = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cmbSingle = new javax.swing.JComboBox();
        txtFile = new javax.swing.JTextField();
        btnBrowse = new javax.swing.JButton();
        chbUseFile = new javax.swing.JCheckBox();
        btnWriteFile = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btnParse.setText("Analyse text");
        btnParse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnParseActionPerformed(evt);
            }
        });

        txaResult.setColumns(20);
        txaResult.setRows(5);
        jScrollPane1.setViewportView(txaResult);

        chbParaphrase.setText("Paraphrase");

        chbDRSProlog.setText("DRS (as a Prolog term)");

        chbDRSXML.setText("DRS XML");

        chbTPTP.setText("TPTP representation of DRS");

        chbFOL.setText("FOL (default form)");

        chbOWLProlog.setText("OWL/SWRL (Functional-Style Syntax, as Prolog term)");

        chbTokens.setText("Tokens");

        chbOWLPP.setText("OWL/SWRL (Functional-Style Syntax, pretty-printed)");

        chbSynTrees.setText("Syntax trees");

        chbGuess.setText("Guess unknown words");

        chbOWLXML.setText("OWL (XML Serialization syntax)");

        chbOWLRDF.setText("OWL/SWRL (RDF/XML syntax)");

        chbSynTreesPPDeb.setText("Syntax trees pretty-printed (for debugging)");

        chbSynTreesDeb.setText("Syntax trees (for debugging)");

        chbSynTreesPP.setText("Syntax trees pretty-printed");

        chbSents.setText("Sentences");

        chbDRSHTML.setText("DRS pretty-printed in HTML");

        chbDRSPT.setText("DRS pretty-printed in plain text");

        chbParaphrase2.setText("Paraphrase2");

        chbParaphrase1.setText("Paraphrase1");

        chbFOLPrenex.setText("FOL (prenex normal form)");

        jPanel2.setBackground(new java.awt.Color(204, 204, 204));

        jLabel1.setText("Other options:");

        jLabel2.setText("Use Single Output");

        cmbSingle.setModel(new javax.swing.DefaultComboBoxModel(new String[] { " ", "Paraphrase", "Paraphrase1", "Paraphrase2", "DRS (as a Prolog term)", "DRS XML", "DRS pretty-printed in plain text", "DRS pretty-printed in HTML", "Tokens", "Sentences", "Syntax trees", "Syntax trees pretty-printed", "Syntax trees (for debugging)", "Syntax trees pretty-printed (for debugging)", "TPTP representation of DRS", "OWL/SWRL (Functional-Style Syntax, as Prolog term)", "OWL/SWRL (Functional-Style Syntax, pretty-printed)", "OWL/SWRL (RDF/XML syntax)", "OWL (XML Serialization syntax)", "FOL (default form)", "FOL (prenex normal form)" }));
        cmbSingle.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbSingleItemStateChanged(evt);
            }
        });

        txtFile.setEnabled(false);

        btnBrowse.setText("Browse...");
        btnBrowse.setEnabled(false);
        btnBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBrowseActionPerformed(evt);
            }
        });

        chbUseFile.setBackground(new java.awt.Color(204, 204, 204));
        chbUseFile.setText("Use text file:");
        chbUseFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chbUseFileActionPerformed(evt);
            }
        });

        btnWriteFile.setText("Write results to file");
        btnWriteFile.setEnabled(false);
        btnWriteFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnWriteFileActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(txtFile, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnBrowse)))
                        .addContainerGap())
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(cmbSingle, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(280, 280, 280))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(475, 475, 475))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(chbUseFile)
                        .addContainerGap(215, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnWriteFile)
                        .addContainerGap(179, Short.MAX_VALUE))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnBrowse)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chbUseFile)))
                .addGap(8, 8, 8)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cmbSingle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnWriteFile)
                .addContainerGap(61, Short.MAX_VALUE))
        );

        jLabel4.setText("Results:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtInput, javax.swing.GroupLayout.PREFERRED_SIZE, 467, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(chbParaphrase)
                            .addComponent(chbParaphrase1)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(chbDRSXML)
                                    .addComponent(chbDRSPT))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(chbOWLPP)
                                    .addComponent(chbSynTreesPPDeb)
                                    .addComponent(chbSynTreesDeb)
                                    .addComponent(chbSynTreesPP)
                                    .addComponent(chbOWLProlog)
                                    .addComponent(chbTPTP)))
                            .addComponent(chbParaphrase2)
                            .addComponent(chbDRSProlog)
                            .addComponent(chbSynTrees)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(chbDRSHTML)
                                    .addComponent(chbTokens)
                                    .addComponent(chbSents))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(chbFOL)
                                    .addComponent(chbOWLXML)
                                    .addComponent(chbOWLRDF)
                                    .addComponent(chbFOLPrenex)))
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(btnParse)
                                .addGap(18, 18, 18)
                                .addComponent(chbGuess))
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnParse)
                    .addComponent(chbGuess))
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(chbParaphrase)
                            .addComponent(chbSynTreesPP))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(chbSynTreesDeb)
                            .addComponent(chbParaphrase1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(chbParaphrase2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chbDRSProlog)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chbDRSXML)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chbDRSPT))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(chbSynTreesPPDeb)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chbTPTP)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chbOWLProlog)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(chbOWLPP, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chbDRSHTML)
                            .addComponent(chbOWLRDF))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chbTokens)
                            .addComponent(chbOWLXML))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chbSents)
                            .addComponent(chbFOL))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(chbSynTrees)
                            .addComponent(chbFOLPrenex))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                        .addComponent(jLabel4))
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnParseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnParseActionPerformed
        // TODO add your handling code here:
        btnWriteFile.setEnabled(true);
        String str = txtInput.getText();
        try {
            //Process proc = Runtime.getRuntime().exec("mspaint"); //proba dali funkcionira. Pushta bilo koe .exe
            String comm = ""; //komanda za da se dade na ape.exe
            //comm += "C:\\Users\\Solev\\Desktop\\WBS_sem\\ape\\ape.exe"; //kade e ape.exe, treba da se smeni vo zavisnost od PC, ili so relativna da se proba

             comm += "C:\\Users\\Solev\\Desktop\\WBS_sem\\ape\\ape.exe";

             if(chbUseFile.isSelected() == true)
            {
                // kod za selekcija na fajl ili vnesuvanje URI na fajl...
                 //./ape.exe -file http://attempto.ifi.uzh.ch/site/acetexts/example1.ace.txt -solo owlxml
                 //./ape.exe -file ace.txt -solo owlfss
                 comm +=" -file ";
                 comm +='"'+txtFile.getText()+'"';//proverka dali txt ema nesto

            }
            else{
            comm += " -text"; //kje obrabotuvame tekst od tekstboksot
            comm += " \"" + str + "\""; //tekstot od tekstboksot
            }

           
            //podesuvanje na opciite za izvrsuvanje

            if(cmbSingle.getSelectedIndex() != 0)
            {
                comm+=" -solo ";
                String[] komanda = { "paraphrase", "paraphrase1", "paraphrase2", "drs", "drsxml", "drspp", "drshtml", "tokens", "sentences", "syntax", "syntaxpp", "syntaxd", "syntaxdpp", "tptp", "owlfss", "owlfsspp", "owlrdf", "owlxml", "fol", "pnf" };

                comm+=komanda[cmbSingle.getSelectedIndex()-1].toString();
               
            }
            else{
            if(chbParaphrase.isSelected() == true) comm += " -cparaphrase";
            if(chbParaphrase1.isSelected() == true) comm += " -cparaphrase1";
            if(chbParaphrase2.isSelected() == true) comm += " -cparaphrase2";
            if(chbDRSProlog.isSelected() == true) comm += " -cdrs";
            if(chbDRSXML.isSelected() == true) comm += " -cdrsxml";
            if(chbDRSPT.isSelected() == true) comm += " -cdrspp";
            if(chbDRSHTML.isSelected() == true) comm += " -cdrshtml";
            if(chbTokens.isSelected() == true) comm += " -ctokens";
            if(chbSents.isSelected() == true) comm += " -csentences";
            if(chbSynTrees.isSelected() == true) comm += " -csyntax";
            
            if(chbSynTreesPP.isSelected() == true) comm += " -csyntaxpp";
            if(chbSynTreesDeb.isSelected() == true) comm += " -csyntaxd";
            if(chbSynTreesPPDeb.isSelected() == true) comm += " -csyntaxdpp";
            if(chbTPTP.isSelected() == true) comm += " -ctptp";
            if(chbOWLProlog.isSelected() == true) comm += " -cowlfss";
            if(chbOWLPP.isSelected() == true) comm += " -cowlfsspp";
            if(chbOWLRDF.isSelected() == true) comm += " -cowlrdf";
            if(chbOWLXML.isSelected() == true) comm += " -cowlxml";
            if(chbFOL.isSelected() == true) comm += " -cfol";
            if(chbFOLPrenex.isSelected() == true) comm += " -cpnf";

            }

            Process proc = Runtime.getRuntime().exec(comm);
            //Process proc = Runtime.getRuntime().exec("C:\\Users\\Solev\\Desktop\\WBS_sem\\ape\\ape.exe -text \"" + str + "\" -cowlrdf");
            //txaResult.append(proc.getInputStream().toString() + "\n");
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            txaResult.setText("");
            String line = "";
            String rez = "";
            String error = "";
            boolean err = false;
            boolean errGlob = false;
            while ((line = in.readLine()) != null) {
                //txaResult.append(line + "\n");
                line = line.replace("&gt;", ">");
                line = line.replace("&lt;", "<");
                if(line.contains("<messages>"))
                {err = true; errGlob = true;}
                else if(line.contains("</messages>")) err = false;
                if(err || line.contains("</messages>")) error += line + " \n";
                else
                rez += line + "\n";
            }
              
//            rez.replace("&gt;", ">");
//            rez.replace("&lt;", "<");
            if(errGlob) {
                txaResult.setText("There were some errors with your ACE text!\n" +
                    "The details are within the <message> tags.\n\n" + error + "\n End of results.");
                rezultat = error;
            }
            else if (!errGlob) {
                txaResult.setText("Success! There were no errors " +
                    "with your ACE text.\n\n" + rez + "\n End of results.");
                rezultat = rez;
            }
            //txaResult.setText(rez + "\n\n\n" + error);
            //obrabotiGreshka(error);
            //txaError.setText(error);
            //lblError.setText(error);
            //txaResult.setFont(Font())
            proc.destroy();

        } catch (Exception ex) {
            txaResult.append(ex.toString() + "\n");
        }

    }//GEN-LAST:event_btnParseActionPerformed

    private void cmbSingleItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbSingleItemStateChanged
        
         if(cmbSingle.getSelectedIndex() != 0)
            {
        chbParaphrase.setEnabled(false);
             chbParaphrase1.setEnabled(false);
              chbParaphrase2.setEnabled(false);
               chbDRSProlog.setEnabled(false);
                chbDRSXML.setEnabled(false);
                 chbDRSPT.setEnabled(false);
                  chbDRSHTML.setEnabled(false);
                   chbTokens.setEnabled(false);
                    chbSents.setEnabled(false);
                     chbSynTrees.setEnabled(false);
                      chbSynTreesPP.setEnabled(false);
                       chbSynTreesDeb.setEnabled(false);
                        chbSynTreesPPDeb.setEnabled(false);
                        chbTPTP.setEnabled(false);
                        chbOWLProlog.setEnabled(false);
                        chbOWLPP.setEnabled(false);
                        chbOWLRDF.setEnabled(false);
                         chbOWLXML.setEnabled(false);
                          chbFOL.setEnabled(false);
                           chbFOLPrenex.setEnabled(false);
         }
         else
         {
             chbParaphrase.setEnabled(true);
             chbParaphrase1.setEnabled(true);
              chbParaphrase2.setEnabled(true);
               chbDRSProlog.setEnabled(true);
                chbDRSXML.setEnabled(true);
                 chbDRSPT.setEnabled(true);
                  chbDRSHTML.setEnabled(true);
                   chbTokens.setEnabled(true);
                    chbSents.setEnabled(true);
                     chbSynTrees.setEnabled(true);
                      chbSynTreesPP.setEnabled(true);
                       chbSynTreesDeb.setEnabled(true);
                        chbSynTreesPPDeb.setEnabled(true);
                        chbTPTP.setEnabled(true);
                        chbOWLProlog.setEnabled(true);
                        chbOWLPP.setEnabled(true);
                        chbOWLRDF.setEnabled(true);
                         chbOWLXML.setEnabled(true);
                          chbFOL.setEnabled(true);
                           chbFOLPrenex.setEnabled(true);
         }
    }//GEN-LAST:event_cmbSingleItemStateChanged

    private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed
        JFileChooser dlg = new JFileChooser("Izberete lexicon");
        if (dlg.showDialog(getContentPane(), "OK") == JFileChooser.APPROVE_OPTION){
            txtFile.setText(dlg.getSelectedFile().toString());
}

    }//GEN-LAST:event_btnBrowseActionPerformed

    private void btnWriteFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnWriteFileActionPerformed
        // TODO add your handling code here:
        try {
            // Create file
            JFileChooser dlg = new JFileChooser("Izberete lexicon");
            if (dlg.showDialog(getContentPane(), "OK") == JFileChooser.APPROVE_OPTION){
            File fajl = new File(dlg.getSelectedFile().toString());
            FileWriter fstream = new FileWriter(fajl); //C:\\Users\\Solev\\Desktop\\
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(rezultat);
            //Close the output stream
            out.close();
            txaResult.setText("Results successfully written to file");
            }
        }
        catch (Exception e){//Catch exception if any
        txaResult.append("Error: " + e.getMessage());
        }
    }//GEN-LAST:event_btnWriteFileActionPerformed

    private void chbUseFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chbUseFileActionPerformed
        // TODO add your handling code here:
        if(chbUseFile.isSelected() == true)
        {
            txtFile.setEnabled(true);
            btnBrowse.setEnabled(true);
        }
        else
        {
            txtFile.setEnabled(false);
            btnBrowse.setEnabled(false);
        }
    }//GEN-LAST:event_chbUseFileActionPerformed

    protected void obrabotiGreshka (String err) {
//        String vazhnost = ""; //error, warning
//        String tip = ""; //owl, sentence, word
//        //String recenica = ""; //koja rechenica e
//        String mesto = ""; // koe mesto (koj token) e problematichen
//        String vrednost = ""; // value
//        String popravka = ""; //repair
        err = err.replaceAll("<messages>", ""); //chistenje na tagovite za poraki
        err = err.replaceAll("</messages>","");
        err = err.replaceAll("/>", "");
        String[] sodrzina = err.split("<message "); //delenje kaj tagot za sekoja poedinechna poraka
                                                    //gi izdvojuvame site poraki
        
        Integer a = sodrzina.length;
        txaResult.append("dolzinata e" + a.toString() + "\n");
        for(int i = 0; i < sodrzina.length; i++)
            sodrzina[i] = sodrzina[i].trim();       //trganje na praznite mesta

        //se pochnuva od sodrzina[1] bidejkji sodrzina[0] posle delenjeto ne sodrzhi nishto osven prazni mesta

        for(Integer i = 1; i < sodrzina.length; i++) {

            txaResult.append("Poraka: " + i.toString() + "\n");
            String [] poraka = sodrzina[i].split("\n");

            for (int j = 0; j < poraka.length; j++)
                poraka[j] = poraka[j].trim();

//        String vazhnost = poraka[0]; //error, warning
//        String tip = poraka[1]; //owl, sentence, word
//        String recenica = poraka[2]; //koja rechenica e
//        String mesto = poraka[3]; // koe mesto (koj token) e problematichen
//        String vrednost = poraka[4]; // value
//        String popravka = poraka[5]; //repair
//
//        vazhnost = vazhnost.replaceAll("importance=", "");
//        vazhnost = vazhnost.replaceAll("\"","");
//
//        tip = tip.replaceAll("type=", "");
//        tip = tip.replaceAll("\"", "");
//
//        recenica = recenica.replaceAll("sentence=", "");
//        recenica = recenica.replaceAll("\"", "");
//
//        mesto = mesto.replaceAll("token=", "");
//        mesto = mesto.replaceAll("\"", "");
//
//        vrednost = vrednost.replaceAll("value=", "");
//        vrednost = vrednost.replaceAll("\"", "");
                
        //popravka = popravka.replaceAll("repair=", "");
        //popravka = popravka.replaceAll("\"", "");

//            for(int j = 0; j < poraka.length; j++)
//                txaResult.append("blabla " + j + poraka[j]+"\n\n");
        }
//
//        for(int i = 0; i < sodrzina.length; i++)
//        txaResult.append(sodrzina[i]+"\n\n");


    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBrowse;
    private javax.swing.JButton btnParse;
    private javax.swing.JButton btnWriteFile;
    private javax.swing.JCheckBox chbDRSHTML;
    private javax.swing.JCheckBox chbDRSPT;
    private javax.swing.JCheckBox chbDRSProlog;
    private javax.swing.JCheckBox chbDRSXML;
    private javax.swing.JCheckBox chbFOL;
    private javax.swing.JCheckBox chbFOLPrenex;
    private javax.swing.JCheckBox chbGuess;
    private javax.swing.JCheckBox chbOWLPP;
    private javax.swing.JCheckBox chbOWLProlog;
    private javax.swing.JCheckBox chbOWLRDF;
    private javax.swing.JCheckBox chbOWLXML;
    private javax.swing.JCheckBox chbParaphrase;
    private javax.swing.JCheckBox chbParaphrase1;
    private javax.swing.JCheckBox chbParaphrase2;
    private javax.swing.JCheckBox chbSents;
    private javax.swing.JCheckBox chbSynTrees;
    private javax.swing.JCheckBox chbSynTreesDeb;
    private javax.swing.JCheckBox chbSynTreesPP;
    private javax.swing.JCheckBox chbSynTreesPPDeb;
    private javax.swing.JCheckBox chbTPTP;
    private javax.swing.JCheckBox chbTokens;
    private javax.swing.JCheckBox chbUseFile;
    private javax.swing.JComboBox cmbSingle;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea txaResult;
    private javax.swing.JTextField txtFile;
    private javax.swing.JTextField txtInput;
    // End of variables declaration//GEN-END:variables

}
